package com.stork.sms.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import android.widget.TextView;

import com.stork.sms.R;

public class MarkListPagerAdapter extends PagerAdapter {

	
	View viewLayout,viewRowHead,viewRowRegnoName,viewRowMarks;
	int  size;
	TextView textDisplay;
	public TableLayout markListTable;
	/*ArrayList<MarkListItems> examNameItem;	
	ArrayList<MarkListItems> quarterlymark;*/
	public String[] cmark=new String[20];
	Activity activity;		
	TextView examNameTextview;
	TableRow Head,nr,row;
		
	public MarkListPagerAdapter(Activity act, String[] marksvalue, int viewPagerSize) {
		// TODO Auto-generated constructor stub	
		this.activity=act;
		//this.examNameItem=examNameItems;
		this.cmark=marksvalue;
		this.size=viewPagerSize;		
	}
		
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return size;
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub		
		return arg0==((View)arg1);
	}
	
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		// TODO Auto-generated method stub	
		
		 LayoutInflater inflater = (LayoutInflater) activity
	                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);		 	
		 
	        viewLayout = inflater.inflate(R.layout.tablepageradapter, null);
	        viewRowHead=inflater.inflate(R.layout.head, null);
	        viewRowRegnoName=inflater.inflate(R.layout.nameregno, null);
	        viewRowMarks=inflater.inflate(R.layout.subjectmarks, null);	        
	        
	        markListTable=(TableLayout)viewLayout.findViewById(R.id.Mark_list);	        
	        int pageno=position+1;      
                  
	       /* Head =((TableRow)viewRowHead);
	        examNameTextview=(TextView)Head.findViewById(R.id.head);
		    examNameTextview.setText(examNameItem.get(position).getExamName());
		    markListTable.addView(Head,new TableLayout.LayoutParams(
	            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));*/
		   
		    nr = ((TableRow)viewRowRegnoName);
		    ((TextView)nr.findViewById(R.id.name)).setText(cmark[2]);
		 ((TextView)nr.findViewById(R.id.regno)).setText(cmark[3]);
		markListTable.addView(nr,new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));				
		if(position==0)
		{
		row = ((TableRow)viewRowMarks);		
	    ((TextView)row.findViewById(R.id.subject)).setText(cmark[5]);	   
	((TextView)row.findViewById(R.id.maxmark)).setText(cmark[6]);
	((TextView)row.findViewById(R.id.minmark)).setText(cmark[7]);
	((TextView)row.findViewById(R.id.markobtained)).setText(cmark[8]);			
	markListTable.addView(row,new TableLayout.LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));	
		}
		else
		{
			row = ((TableRow)viewRowMarks);		
		    ((TextView)row.findViewById(R.id.subject)).setText(cmark[10]);	   
		((TextView)row.findViewById(R.id.maxmark)).setText(cmark[11]);
		((TextView)row.findViewById(R.id.minmark)).setText(cmark[12]);
		((TextView)row.findViewById(R.id.markobtained)).setText(cmark[13]);			
		markListTable.addView(row,new TableLayout.LayoutParams(
	            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		}

   		
			((ViewPager) container).addView(viewLayout);		
	        return viewLayout;
		 		
		}
	
	@Override
	public void destroyItem(View container, int position, Object object) {
		// TODO Auto-generated method stub
		((ViewPager)container).removeView((View)object);
	}   
	    	
	      
	}
